package com.huangguolin.cloud.spring.security;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

@Component
public class GdmtPasswordEncoder implements PasswordEncoder {

    @Value("${passwd.key}")
    private String passwdKey;

    @Override
    public String encode(CharSequence charSequence) {
        return DigestUtils.md5DigestAsHex((charSequence + passwdKey).getBytes());
    }
    @Override
    public boolean matches(CharSequence charSequence, String dbPsawo) {
        return dbPsawo.equals(encode(charSequence));
    }

}
